home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / VLIB200.ZIP / VLIBDEMO.C < prev    next >
C/C++ Source or Header  |  1993-10-29  |  71KB  |  2,275 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM:    Vlibdemo.exe
  4.  
  5.     PURPOSE:    To demonstrate the usage of Visualib(TM) functions.
  6.     
  7.     PROVIDER:   Visual Technology, Co.
  8.                 P.O.Box 901-413
  9.                 Kansas City, MO 64190
  10.                 Tel. (219) 289-0235
  11.                 Fax. (816) 746-6618
  12.     
  13.     DATE:        May, 1993
  14.  
  15. ****************************************************************************/
  16.  
  17. #include <windows.h>
  18. #include <math.h>
  19. #include "visualib.h"
  20. #include "menu.h"
  21. #include "vlibdemo.h"
  22. #include "demoproc.h"
  23. #include "dialogs.h"
  24.  
  25. HINSTANCE    hInst;
  26. HPALETTE    hpal;
  27. short   viewer20, viewer21, viewer22;
  28. short   viewer30, viewer31, viewer32, viewer33, viewer34, viewer35;
  29. short   demo_function, animate_length;
  30. short   light0, light1, light2, light3, light4, light5, light6, light7, light8;
  31. short   mater0, mater1, mater2, mater3, mater4, mater5, mater6, mater7;
  32. HGLOBAL hdib1, hdib2, hdib3;
  33. COLORREF    backcolor;
  34. BOOL    withframe = FALSE;
  35.  
  36. void    FunctionDemos (HDC hdc); 
  37.  
  38. int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int nCmdShow)
  39. {
  40.     MSG msg;
  41.  
  42.     if (hPrev)
  43.         return (FALSE);
  44.  
  45.     if (!InitApplication (hInst))
  46.         return (FALSE);
  47.     
  48.     if (!InitInstance (hInst, nCmdShow))
  49.         return (FALSE);
  50.     
  51.     while (GetMessage (&msg, NULL, NULL, NULL)) {
  52.         TranslateMessage (&msg);
  53.         DispatchMessage (&msg);
  54.     }
  55.     return (msg.wParam);
  56. }
  57.  
  58. void    ViewerReset ()
  59. {
  60.     RECT    port;
  61.  
  62.     SetViewerName (viewer21, "2D Objects");
  63.     SetRect (&port, 10, 10, 110, 110);
  64.     SetViewport (viewer21, port);
  65.     SetWindow2D (viewer21, -10, -10, 10, 10);
  66.  
  67.     SetViewerName (viewer22, "U.S. Flag");
  68.     SetRect (&port, 10, 10, 410, 227);
  69.     SetViewport (viewer22, port);
  70.     SetWindow2D (viewer22, 0, 0, 1, (real) (13.0 / 24.0));
  71.  
  72.     SetViewerName (viewer31, "View Motion");
  73.     SetRect (&port, 120, 10, 220, 110);
  74.     SetViewport (viewer31, port);
  75.     SetView3D (viewer31, 100, 100, 100, 0, 0, 0, 0);
  76.     SetPerspective (viewer31, 45, 1, 1, 1000);
  77.  
  78.     SetViewerName (viewer32, "Object Rotation");
  79.     SetRect (&port, 230, 10, 330, 110);
  80.     SetViewport (viewer32, port);
  81.     SetView3D (viewer32, 100, 100, 100, 0, 0, 0, 0);
  82.     SetPerspective (viewer32, 45, 1, 1, 1000);
  83.  
  84.     SetViewerName (viewer33, "View Zoom");
  85.     SetRect (&port, 230, 130, 330, 230);
  86.     SetViewport (viewer33, port);
  87.     SetPolarView (viewer33, 1, 1, 0, 20, 75, 45, 0);
  88.     SetPerspective (viewer33, 90, 1, 1, 1000);
  89.  
  90.     SetViewerName (viewer34, "Ortho Project");
  91.     SetRect (&port, 120, 130, 220, 230);
  92.     SetViewport (viewer34, port);
  93.     SetPolarView (viewer34, 0, 0, 0, 10, 45, 45, 0);
  94.     SetProjection3D (viewer34, -10, -10, 10, 10, 1, 100, VL_ORTHOGONAL);
  95.  
  96.     SetViewerName (viewer35, "Depth Clipping");
  97.     SetRect (&port, 10, 130, 110, 230);
  98.     SetViewport (viewer35, port);
  99.     SetPolarView (viewer35, 0, 0, 0, 20, 75, 45, 0);
  100.     SetPerspective (viewer35, 90, 1, 1, 80);
  101. }
  102.  
  103. /****************************************************************************
  104.  
  105.     FUNCTION: InitApplication (HANDLE)
  106.  
  107.     PURPOSE: Initializes window data and registers window class
  108.  
  109.     COMMENTS:
  110.  
  111.         This function is called at initialization time only if no other 
  112.         instances of the application are running.  This function performs 
  113.         initialization tasks that can be done once for any number of running 
  114.         instances.  
  115.  
  116.         In this case, we initialize a window class by filling out a data 
  117.         structure of type WNDCLASS and calling the Windows RegisterClass () 
  118.         function.  Since all instances of this application use the same window
  119.         class, we only need to do this when the first instance is initialized.
  120.  
  121. ****************************************************************************/
  122.  
  123. BOOL InitApplication (HINSTANCE hInstance)
  124. {
  125.     WNDCLASS  wc;
  126.     RECT    port;
  127.     VECTOR3    parameter;
  128.  
  129.     if (!InitializeVisualib ())
  130.         return (FALSE);
  131.     SelectLight (light0 = CreateLight (NULL, VL_POINTLIGHT));
  132.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  133.     VSET3 (parameter, 50, 250, 0);
  134.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  135.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  136.     SwitchLight (VL_CURRENT, TRUE);
  137.  
  138.     SelectLight (light1 = CreateLight (NULL, VL_POINTLIGHT));
  139.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  140.     VSET3 (parameter, 350, -100, 200);
  141.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  142.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  143.     SwitchLight (VL_CURRENT, TRUE);
  144.  
  145.     SelectLight (light2 = CreateLight (NULL, VL_POINTLIGHT));
  146.     VSET3 (parameter, -50, 0, 0);
  147.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  148.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (51, 255, 51));
  149.  
  150.     SelectLight (light3 = CreateLight (NULL, VL_POINTLIGHT));
  151.     VSET3 (parameter, 250, -20, 0);
  152.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  153.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (51, 51, 255));
  154.  
  155.     SelectLight (light4 = CreateLight (NULL, VL_SPOTLIGHT));
  156.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  157.     VSET3 (parameter, 0, 100, 100);
  158.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  159.     VSET3 (parameter, 0, -0.707, -0.707);
  160.     ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  161.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  162.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  163.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 0, 0));
  164.  
  165.     SelectLight (light5 = CreateLight (NULL, VL_SPOTLIGHT));
  166.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  167.     VSET3 (parameter, 100, 0, 100);
  168.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  169.     VSET3 (parameter, -0.707, 0, -0.707);
  170.     ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  171.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  172.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  173.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (0, 255, 0));
  174.  
  175.     SelectLight (light6 = CreateLight (NULL, VL_SPOTLIGHT));
  176.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  177.     VSET3 (parameter, 100, 100, 100);
  178.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  179.     VSET3 (parameter, -0.577, -0.577, -0.577);
  180.     ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  181.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  182.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  183.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (0, 0, 255));
  184.  
  185.     SelectLight (light7 = CreateLight (NULL, VL_POINTLIGHT));
  186.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  187.     VSET3 (parameter, 50, 250, 0);
  188.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  189.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  190.  
  191.     SelectLight (light8 = CreateLight (NULL, VL_POINTLIGHT));
  192.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  193.     VSET3 (parameter, 350, -100, 200);
  194.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  195.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  196.  
  197.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_PHONGSHADE);
  198.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  199.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  200.     ShadingOption (VL_CURRENT, VL_LOCALVIEWER, TRUE);
  201.  
  202.     SelectMaterial (mater0 = CreateMaterial (NULL));
  203.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  204.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  205.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  206.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.2f);
  207.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (255, 255, 255));
  208.     ShadingFactor (VL_CURRENT, VL_SHININESS, 30);
  209.  
  210.     SelectMaterial (mater1 = CreateMaterial (NULL));
  211.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  212.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 0, 0));
  213.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.3f);
  214.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (255, 0, 0));
  215.     ShadingFactor (VL_CURRENT, VL_SHININESS, 40);
  216.  
  217.     SelectMaterial (mater2 = CreateMaterial (NULL));
  218.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  219.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  220.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.4f);
  221.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (0, 255, 0));
  222.     ShadingFactor (VL_CURRENT, VL_SHININESS, 20);
  223.  
  224.     SelectMaterial (mater3 = CreateMaterial (NULL));
  225.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  226.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 0.5f);
  227.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  228.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.1f);
  229.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (0, 0, 255));
  230.     ShadingFactor (VL_CURRENT, VL_SHININESS, 10);
  231.     mater4 = CreateMaterial (NULL);
  232.     mater5 = CreateMaterial (NULL);
  233.     mater6 = CreateMaterial (NULL);
  234.     mater7 = CreateMaterial (NULL);
  235.     SelectMaterial (mater0);
  236.  
  237.     hpal = SetRGBPalette ();
  238.     SetRect (&port, 0, 0, 400, 300);
  239.     viewer20 = CreateViewer ("2D Primitive Test", port, VL_TWOD, VL_HORZFIT);
  240.     SetWindow2D (viewer20, -10, -10, 10, 10); 
  241.     viewer30 = CreateViewer ("3D Primitive Test", port, VL_THREED, VL_HORZFIT);
  242.     SetView3D (viewer30, 100, 100, 100, 0, 0, 0, 0);
  243.     SetPerspective (viewer30, 45, 1, 30, 1000);
  244.     SetDepthBuffer (viewer30);
  245.  
  246.     viewer21 = CreateViewer ("2D Objects", port, VL_TWOD, VL_HORZFIT);
  247.     viewer22 = CreateViewer ("U.S. Flag", port, VL_TWOD, VL_ALLFIT);
  248.     viewer31 = CreateViewer ("View Motion", port, VL_THREED, VL_ALLFIT);
  249.     viewer32 = CreateViewer ("Object Rotation", port, VL_THREED, VL_ALLFIT);
  250.     viewer33 = CreateViewer ("View Zoom", port, VL_THREED, VL_ALLFIT);
  251.     viewer34 = CreateViewer ("Ortho Project", port, VL_THREED, VL_HORZFIT);
  252.     viewer35 = CreateViewer ("Depth Clipping", port, VL_THREED, VL_ALLFIT);
  253.     ViewerReset ();
  254.     demo_function = IDM_DEMO_START;
  255. //    demo_function = 0;
  256.     wc.style = NULL;
  257.     wc.lpfnWndProc = MainWndProc;
  258.     wc.cbClsExtra = 0;
  259.     wc.cbWndExtra = 0;
  260.     wc.hInstance = hInstance;
  261.     wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (VL_LOGO));
  262.     wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  263.     backcolor = RGB (0, 64, 64);
  264.     wc.hbrBackground = CreateSolidBrush (backcolor);
  265.     wc.lpszMenuName = "VlibDemo";
  266.     wc.lpszClassName = "VlibDemoClass";
  267.  
  268.     return (RegisterClass (&wc));
  269.  
  270. }
  271.  
  272. /****************************************************************************
  273.  
  274.     FUNCTION:  InitInstance (HANDLE, int)
  275.  
  276.     PURPOSE:  Saves instance handle and creates main window
  277.  
  278.     COMMENTS:
  279.  
  280.         This function is called at initialization time for every instance of 
  281.         this application.  This function performs initialization tasks that 
  282.         cannot be shared by multiple instances.  
  283.  
  284.         In this case, we save the instance handle in a static variable and 
  285.         create and display the main program window.  
  286.     
  287. ****************************************************************************/
  288.  
  289. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
  290. {
  291.     HWND    hWnd;
  292.     int     sw, sh, ww, wh;
  293.  
  294.     sw = GetSystemMetrics (0);
  295.     sh = GetSystemMetrics (1);
  296.     hInst = hInstance;
  297.  
  298.     ww = (int) (sw * 0.8);
  299.     wh = (int) (sh * 0.8);
  300.     sw = (int) (sw * 0.1);
  301.     sh = (int) (sh * 0.1);
  302.     hWnd = CreateWindow ("VlibDemoClass",
  303.         "Visualib 2.0 Demonstration",
  304.         WS_OVERLAPPEDWINDOW, sw, sh, ww, wh,
  305.         NULL, NULL, hInstance, NULL);
  306.  
  307.     if (!hWnd)
  308.         return (FALSE);
  309.  
  310.     ShowWindow (hWnd, nCmdShow);
  311.     UpdateWindow (hWnd);
  312.     PostMessage (hWnd, WM_COMMAND, IDM_DEMO_WITHFRAME, 0L);
  313.     return (TRUE);
  314. }
  315.  
  316. POINT3D surf[16] = {
  317.     {-3, 0, 1}, {2, 1, 0}, {5, 0, 0}, {8, 0, 2},
  318.     {-2, 2, 3}, {1, 4, 3}, {6, 4, 1}, {7, 2, 1},
  319.     {-2, 5, 5}, {1, 7, 3}, {5, 5, 2}, {7, 6, 3},
  320.     {-2, 8, 8}, {2, 9, 0}, {4, 7, 4}, {8, 9, 9}
  321. };
  322.  
  323. real    sknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  324. real    tknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  325.  
  326. void    ObjectMotion2D (HDC hdc)
  327. {
  328.     short   i;
  329.  
  330.     SelectViewer (viewer21);
  331.     PenColor (hdc, VL_BLUE);
  332.     DisplayViewerFrame (hdc, VL_CURRENT);
  333.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  334.     DisplayViewerName (hdc, VL_CURRENT, 0);
  335.  
  336.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  337.  
  338.     PenColor (hdc, VL_RED);
  339.     for (i = 0; i < 5 * animate_length; i ++) {
  340.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  341.         BrushColor (hdc, VL_GREEN);
  342.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  343.         BrushColor (hdc, VL_RED);
  344.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  345.         Rotate2D (6);
  346.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  347.     }
  348.     for (i = 0; i < 5 * animate_length; i ++) {
  349.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  350.         BrushColor (hdc, VL_GREEN);
  351.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  352.         BrushColor (hdc, VL_RED);
  353.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  354.         MoveViewer2D (VL_CURRENT, (real)0.25, 0, TRUE);
  355.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  356.     }
  357.  
  358.     for (i = 0; i < 5 * animate_length; i ++) {
  359.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  360.         BrushColor (hdc, VL_GREEN);
  361.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  362.         BrushColor (hdc, VL_RED);
  363.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  364.         Scale2D ((real)1.06, (real)1.06);
  365.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  366.     }
  367.     EndDoubleBuffer (&hdc, VL_CURRENT);
  368. }
  369.  
  370. void    ViewerMotion3D (HDC hdc)
  371. {
  372.     short   i, depthbuffer, shadingmethod;
  373.  
  374.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  375.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  376.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  377.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  378.     SelectViewer (viewer31);
  379.     PenColor (hdc, VL_BLUE);
  380.     DisplayViewerFrame (hdc, VL_CURRENT);
  381.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  382.     DisplayViewerName (hdc, VL_CURRENT, 0);
  383.  
  384.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  385.     SelectMaterial (mater1);
  386.     PenColor (hdc, VL_NONE);
  387.     for (i = 0; i < 3 * animate_length; i ++) {
  388.         MoveViewer3D (VL_CURRENT, 0, 0, -10, TRUE);
  389.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  390.         if (Cube (hdc, 50, 50, 25))
  391.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  392.         else
  393.             goto exit;
  394.     }
  395.     SelectMaterial (mater2);
  396.     for (i = 0; i < 3 * animate_length; i ++) {
  397.         MoveViewer3D (VL_CURRENT, 0, 5, 0, TRUE);
  398.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  399.         if (Cube (hdc, 50, 50, 25))
  400.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  401.         else
  402.             goto exit;
  403.     }
  404.     SelectMaterial (mater3);
  405.     for (i = 0; i < 3 * animate_length; i ++) {
  406.         MoveViewer3D (VL_CURRENT, 5, 0, 0, TRUE);
  407.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  408.         if (Cube (hdc, 50, 50, 25))
  409.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  410.         else
  411.             goto exit;
  412.     }
  413.     SelectMaterial (mater0);
  414.     for (i = 0; i < 5 * animate_length; i ++) {
  415.         RotateViewer3D (VL_CURRENT, 6, 'z', FALSE);
  416.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  417.         if (!Cube (hdc, 50, 50, 25))
  418.             goto exit;
  419.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  420.     }
  421.     SelectMaterial (mater1);
  422.     for (i = 0; i < 5 * animate_length; i ++) {
  423.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  424.         RotateViewer3D (VL_CURRENT, 6, 'y', FALSE);
  425.         if (Cube (hdc, 50, 50, 25))
  426.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  427.         else
  428.             goto exit;
  429.     }
  430.     SelectMaterial (mater2);
  431.     for (i = 0; i < 5 * animate_length; i ++) {
  432.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  433.         RotateViewer3D (VL_CURRENT, 6, 'x', FALSE);
  434.         if (Cube (hdc, 50, 50, 25))
  435.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  436.         else
  437.             goto exit;
  438.     }
  439. exit:
  440.     EndDoubleBuffer (&hdc, VL_CURRENT);
  441.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  442.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  443. }
  444.  
  445. void    ObjectMotion3D (HDC hdc)
  446. {
  447.     short   i, depthbuffer, shadingmethod;
  448.  
  449.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  450.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  451.     SelectViewer (viewer32);
  452.     PenColor (hdc, VL_BLUE);
  453.     DisplayViewerFrame (hdc, VL_CURRENT);
  454.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  455.     DisplayViewerName (hdc, VL_CURRENT, 0);
  456.  
  457.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  458.  
  459.     SelectMaterial (mater1);
  460.     PenColor (hdc, VL_NONE);
  461.     for (i = 0; i <= 5 * animate_length; i ++) {
  462.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  463.         if (Cylinder (hdc, 30, 40, 50)) {
  464.             Rotate3D (3, 'z');
  465.             Rotate3D (6, 'x');
  466.             Rotate3D (3, 'y');
  467.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  468.         }
  469.         else
  470.             break;
  471.     }
  472.     EndDoubleBuffer (&hdc, VL_CURRENT);
  473.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  474.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  475. }
  476.  
  477. void    ViewerZoom3D (HDC hdc)
  478. {
  479.     short   i, depthbuffer, shadingmethod;
  480.     POINT3D p = {0, 0, 0};
  481.  
  482.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  483.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);    ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  484.     SelectViewer (viewer33);
  485.     PenColor (hdc, VL_RED);
  486.     DisplayViewerFrame (hdc, VL_CURRENT);
  487.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  488.     DisplayViewerName (hdc, VL_CURRENT, 0);
  489.  
  490.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  491.  
  492.     SelectMaterial (mater2);
  493.     PenColor (hdc, VL_NONE);
  494.     for (i = 0; i < 5 * animate_length; i ++) {
  495.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  496.         if (Cone (hdc, 3, 5, 10)) {
  497.             ZoomViewer3D (VL_CURRENT, 1.05f);
  498.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  499.         }
  500.         else
  501.             break;
  502.     }
  503.     EndDoubleBuffer (&hdc, VL_CURRENT);
  504.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  505.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  506. }
  507.  
  508. void    OrthoProject3D (HDC hdc)
  509. {
  510.     POINT3D p = {3, -1, -4};
  511.  
  512.     PenColor (hdc, VL_RED);
  513.     DisplayViewerFrame (hdc, viewer34);
  514.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  515.     DisplayViewerName (hdc, viewer34, 0);
  516.     SelectViewer (viewer34);
  517.     SelectMaterial (mater3);
  518.     PenColor (hdc, VL_NONE);
  519.     Ellipsoid (hdc, 3, 4, 5);
  520. }
  521.  
  522. void    RotateStar (HDC hdc)
  523. {
  524.     short   i;
  525.     BOOL    depthbuffer, shadingmethod;
  526.  
  527.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  528.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  529.     PenColor (hdc, VL_RED);
  530.     DisplayViewerFrame (hdc, viewer35);
  531.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  532.     DisplayViewerName (hdc, viewer35, 0);
  533.  
  534.     SelectViewer (viewer35);
  535.     BeginDoubleBuffer (&hdc, viewer35);
  536.     PenColor (hdc, VL_NONE);
  537.     for (i = 0; i < 5 * animate_length; i ++) {
  538.         ClearViewer (hdc, viewer35, VL_GRAY);
  539.         if (SolidStar (hdc, 5, 20, 20, 5)) {
  540.             MoveViewer3D (viewer35, 0, 0, (real)-0.5, TRUE);
  541.             Rotate3D (6 * i, 'z');
  542.             UpdateDoubleBuffer (hdc, viewer35);
  543.         }
  544.         else
  545.             break;
  546.     }
  547.     EndDoubleBuffer (&hdc, viewer35);
  548.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  549.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  550. }
  551.  
  552. void CompositeDemo2D (HDC hdc)
  553. {
  554.     RECT    orgport, newport;
  555.  
  556.     SelectViewer (viewer22);
  557.     PenColor (hdc, VL_BLACK);
  558.     DisplayViewerFrame (hdc, VL_CURRENT);
  559.     USFlag (hdc);
  560.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  561.     DisplayViewerName (hdc, VL_CURRENT, 0);
  562.  
  563.     GetViewport (VL_CURRENT, &orgport);
  564.     SetRect (&newport, 350, 230, 410, 260);
  565.     SetViewport (VL_CURRENT, newport);
  566.     USFlag (hdc);
  567.     PenColor (hdc, VL_BLACK);
  568.     DisplayViewerFrame (hdc, VL_CURRENT);
  569.     SetViewport (VL_CURRENT, orgport);
  570. }
  571.  
  572. void    RotateSpring (HDC hdc)
  573. {
  574.     short   i, depthbuffer, shadingmethod;
  575.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  576.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  577.     SelectViewer (viewer31);
  578.     PenColor (hdc, VL_BLUE);
  579.     DisplayViewerFrame (hdc, VL_CURRENT);
  580.     SetViewerName (VL_CURRENT, "3D Curve");
  581.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  582.     DisplayViewerName (hdc, VL_CURRENT, 0);
  583.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  584.     Scale3D (20, 20, 20);
  585.     for (i = 0; i < 5 * animate_length; i ++) {
  586.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  587.         PenColor (hdc, VL_BLUE);
  588.         Spring (hdc, 3, 2, 0.5f);
  589.         Translate3D (0.05f, 0, 0);
  590.         Rotate3D (-6, 'y');
  591.         PushTransformation3D (NULL);
  592.         SelectMaterial (mater0);
  593.         PenColor (hdc, VL_NONE);
  594.         Rotate3D (6 * i, 'z');
  595.         Translate3D (0, 2, 0);
  596.         Rotate3D (3, 'y');
  597.         if (!Tetrahedron (hdc, 1))
  598.             break;
  599.         PushTransformation3D (NULL);
  600.         SelectMaterial (mater1);
  601.         Rotate3D (6, 'x');
  602.         Translate3D (0, 0, 2);
  603.         Rotate3D (3 * i, 'z');
  604.         if (!Octahedron (hdc, 1))
  605.             break;
  606.         PopTransformation3D (NULL);
  607.         PopTransformation3D (NULL);
  608.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  609.     }
  610.     EndDoubleBuffer (&hdc, VL_CURRENT);
  611.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  612.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  613. }
  614.  
  615. void    RotateFrame (HDC hdc)
  616. {
  617.     short   i;
  618.     COORD    point[] = {0, 0, 0, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1,
  619.         1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1,
  620.         -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1,
  621.         0, 0, 0, 1, -1, 1, -1, -1, -1, 0, 0, 0};
  622.     
  623.     PenColor (hdc, VL_BLUE);
  624.     SelectViewer (viewer32);
  625.     DisplayViewerFrame (hdc, VL_CURRENT);
  626.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  627.     Scale3D (30, 30, 30);
  628.     PenColor (hdc, VL_BLUE);
  629.     for ( i = 0; i < 5 * animate_length; i++) {
  630.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  631.         Polyline3D (hdc, VL_3D, point, 19);
  632.         Rotate3D (6, 'z');
  633.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  634.     }
  635.     EndDoubleBuffer (&hdc, VL_CURRENT);
  636. }
  637.  
  638. void    RotateSurface (HDC hdc)
  639. {
  640.     short   i, depthbuffer, shadingmethod;
  641.  
  642.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  643.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  644.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  645.     SelectViewer (viewer35);
  646.     PenColor (hdc, VL_BLUE);
  647.     DisplayViewerFrame (hdc, VL_CURRENT);
  648.     SetViewerName (VL_CURRENT, "NURBS Surface");
  649.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  650.     DisplayViewerName (hdc, VL_CURRENT, 0);
  651.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  652.     PenColor (hdc, VL_MAGENTA);
  653.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  654.     for (i = 0; i < 5 * animate_length; i++) {
  655.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  656.         if (!NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 4, 4, sknot, tknot, 8, 8))
  657.             break;
  658.         Rotate3D (6, 'z');
  659.         Rotate3D (12, 'x');
  660.         Rotate3D (3, 'y');
  661.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  662.     }
  663.     EndDoubleBuffer (&hdc, VL_CURRENT);
  664.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  665.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  666.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  667. }
  668.  
  669. void    RotateDodecahedron (HDC hdc)
  670. {
  671.     short   i, depthbuffer, shadingmethod;
  672.  
  673.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  674.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  675.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  676.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  677.     SelectViewer (viewer33);
  678.     PenColor (hdc, VL_RED);
  679.     DisplayViewerFrame (hdc, VL_CURRENT);
  680.     SetViewerName (VL_CURRENT, "Dodecahedron");
  681.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  682.     DisplayViewerName (hdc, VL_CURRENT, 0);
  683.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  684.     Scale3D (6, 6, 6);
  685.     BrushColor (hdc, VL_BROWN);
  686.     PenColor (hdc, VL_NONE);
  687.     for (i = 0; i < 5 * animate_length; i ++) {
  688.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  689.         if (!Dodecahedron (hdc, 0.5f))
  690.             break;
  691.         Translate3D (0, (real)0.1, 0);
  692.         Rotate3D (6, 'z');
  693.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  694.     }
  695.     EndDoubleBuffer (&hdc, VL_CURRENT);
  696.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  697.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  698. }
  699.  
  700. void    RotateIcosahedron (HDC hdc)
  701. {
  702.     short   i, depthbuffer, shadingmethod;
  703.  
  704.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  705.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  706.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  707.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  708.     SelectViewer (viewer34);
  709.     PenColor (hdc, VL_RED);
  710.     DisplayViewerFrame (hdc, VL_CURRENT);
  711.     SetViewerName (VL_CURRENT, "Icosahedron");
  712.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  713.     DisplayViewerName (hdc, VL_CURRENT, 0);
  714.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  715.     Scale3D (3, 3, 3);
  716.     BrushColor (hdc, VL_YELLOW);
  717.     PenColor (hdc, VL_NONE);
  718.     for (i = 0; i < 5 * animate_length; i ++) {
  719.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  720.         if (Icosahedron (hdc, 1)) {
  721.             Rotate3D (3, 'y');
  722.             Translate3D ((real)0.1, 0, 0);
  723.             Rotate3D (6, 'z');
  724.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  725.         }
  726.         else
  727.             break;
  728.     }
  729.     EndDoubleBuffer (&hdc, VL_CURRENT);
  730.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  731.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  732. }
  733.  
  734. void    Surfaces (HDC hdc, WORD cmd)
  735. {
  736.     SelectViewer (viewer30);
  737.     ClearDepthBuffer (0xffff);
  738.     if (ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_INQUIRE) == VL_WIREFRAME) {
  739.         PenColor (hdc, VL_RED);
  740.     }
  741.     else {
  742.         ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  743.         PenColor (hdc, VL_NONE);
  744.     }
  745.  
  746.     PushTransformation3D (NULL);
  747.     switch (cmd) {
  748.         case IDM_SURFACE_BEZIER:
  749.         {
  750.             POINT3D surf[16] = {
  751.                 {0, 6, 3}, {2, 6, 0}, {4, 6, 2}, {6, 6, 0},
  752.                 {0, 4, 0}, {2, 4, 5}, {4, 4, 0}, {6, 4, 6},
  753.                 {0, 2, 5}, {2, 2, 0}, {4, 2, 6}, {6, 2, 0},
  754.                 {0, 0, 0}, {2, 0, 3}, {4, 0, 0}, {6, 0, 3}};
  755.  
  756.             Scale3D (5, 5, 5);
  757.             BezierSurface (hdc, VL_3D, (LPCOORD) surf, 16, 16);
  758.             PenColor (hdc, VL_GREEN);
  759.             Net3D (hdc, VL_3D, (LPCOORD) surf, 4, 4);
  760.             PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 16, 2, 2, VL_CIRCLEMARK);
  761.             break;
  762.         }
  763.         case IDM_SURFACE_HERMIT:
  764.         {
  765.             POINT3D surf[16] = {
  766.                 {0, 0, 0}, {0, 6, 0}, {0, 6, 6}, {0, 6, -2},
  767.                 {6, 0, 0}, {6, 6, 0}, {0, 2, 2}, {0, 6, -2},
  768.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0},
  769.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0}};
  770.  
  771.             Scale3D (5, 5, 5);
  772.             HermitSurface (hdc, VL_3D, (LPCOORD) surf, 16, 16);
  773.             PenColor (hdc, VL_GREEN);
  774. //            Net3D (hdc, VL_3D, (LPCOORD) surf, 4, 4);
  775. //            PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 16, 2, 2, VL_DIAMONDMARK);
  776.             break;
  777.         }
  778.         case IDM_SURFACE_BSPLINE:
  779.         {
  780.             break;
  781.         }
  782.         case IDM_SURFACE_NURBS:
  783.         {
  784.             POINT3D surf[36] = {
  785.                 {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  786.                 {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  787.                 {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  788.                 {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  789.                 {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  790.                 {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  791.             real    sknot[20] = {0,0,0,1,2,3,3,3};
  792.             real    tknot[20] = {0,0,0,1,2,3,3,3};
  793.  
  794.             SwitchLight (light0, FALSE);
  795.             SwitchLight (light1, FALSE);
  796.             SwitchLight (light4, TRUE);
  797.             Scale3D (10, 10, 5);
  798.             Translate3D (-3, -2, 0);
  799.             NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 6, 6, sknot, tknot, 4, 4);
  800.             PenColor (hdc, VL_GREEN);
  801.             Net3D (hdc, VL_3D, (LPCOORD) surf, 6, 6);
  802.             PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 36, 2, 2, VL_BOXMARK);
  803.             break;
  804.         }
  805.         case IDM_SURFACE_COONSPATCH:
  806.         {
  807.             POINT3D    point[] = {{0,0,4},{1,-2,3},{2,-2,2},{3,0,1},
  808.                                {4,0,0},{4,1,0},{4,2,0},{4,3,0},
  809.                                {4,4,0},{3,4,0},{2,4,0},{1,4,0},
  810.                                {0,4,0},{0,3,1},{-2,2,2},{-2,1,3}};
  811.             Scale3D (5, 5, 5);
  812.             CoonsPatch (hdc, VL_3D, (LPCOORD) point, 5, 5);
  813. /*
  814.             POINT3D    cpu0[]={{0,0,4},{1,0,3},{2,0,2},{3,0,1},{4,0,0}};
  815.             POINT3D    cpu1[]={{0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0}};
  816.             POINT3D    cpv0[]={{0,0,4},{0,1,3},{0,2,2},{0,3,1},{0,4,0}};
  817.             POINT3D    cpv1[]={{4,0,0},{4,1,0},{4,2,0},{4,3,0},{4,4,0}};
  818.             Scale3D (5, 5, 2);
  819.             CoonsPatch (hdc, cpu0, cpu1, 5, cpv0, cpv1, 5);
  820. */
  821.             break;
  822.         }
  823.     }
  824.     PopTransformation3D (NULL);
  825. }
  826.  
  827. void    Curves3D (HDC hdc, WORD cmd)
  828. {
  829.     POINT3D curve[16] = {
  830.         {0, 0, 0}, {20, -30, 30}, {40, 30, -30}, {60, 0, 0},
  831.         {0, 4, 0}, {2, 4, 5}, {4, 4, 0}, {6, 4, 6},
  832.         {0, 2, 5}, {2, 2, 0}, {4, 2, 6}, {6, 2, 0},
  833.         {0, 0, 0}, {2, 0, 3}, {4, 0, 0}, {6, 0, 3}};
  834.     COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  835.     real Knot1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  836.     real Knot2[] = {0, 0, 0, 1, 1, 1, 4, 5, 5, 5};
  837.     real Knot3[] = {0, 0, 0, 1, 1, 1, 1, 2, 3, 4, 5, 6};
  838.     real Knot4[] = {0, 0, 0, 1, 3, 5, 7, 9, 10, 15};
  839.  
  840.     SelectViewer (viewer30);
  841.     ClearDepthBuffer (0xffff);
  842.     PushTransformation3D (NULL);
  843.     switch (cmd) {
  844.         case IDM_3DCURVE_SPRING:
  845.             MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  846.             PenColor (hdc, VL_BLUE);
  847.             Spring3D (hdc, 30, 10, 10, 40);
  848.             PenColor (hdc, VL_YELLOW);
  849.             Rotate3D (90, 'y');
  850.             Spring3D (hdc, 30, 10, 10, 40);
  851.             PenColor (hdc, VL_GREEN);
  852.             Rotate3D (-90, 'x');
  853.             Spring3D (hdc, 30, 10, 10, 40);
  854.             SetViewerName (VL_CURRENT, "3D Springs");
  855.             break;
  856.         case IDM_3DCURVE_SPIRAL:
  857.             MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  858.             PenColor (hdc, VL_GREEN);
  859.             Spiral3D (hdc, 0, 10, 0, 0.5f, 40);
  860.             PenColor (hdc, VL_YELLOW);
  861.             Rotate3D (90, 'y');
  862.             Spiral3D (hdc, 0, 10, 0, 0.5f, 40);
  863.             PenColor (hdc, VL_RED);
  864.             Rotate3D (-90, 'x');
  865.             Spiral3D (hdc, 0, 10, 0, 0.5f, 40);
  866.             SetViewerName (VL_CURRENT, "3D Spiral");
  867.             break;
  868.         case IDM_3DCURVE_BEZIER:
  869.             PenColor (hdc, VL_GREEN);
  870.             BezierCurve3D (hdc, VL_3D, (LPCOORD) curve);
  871.             SetViewerName (VL_CURRENT, "3D Bezier Curve");
  872.             break;
  873.         case IDM_3DCURVE_HERMIT:
  874.             PenColor (hdc, VL_GREEN);
  875.             HermitCurve3D (hdc, VL_3D, (LPCOORD) curve);
  876.             SetViewerName (VL_CURRENT, "3D Hermit Curve");
  877.             break;
  878.         case IDM_3DCURVE_BSPLINE:
  879.             PenColor (hdc, VL_GREEN);
  880.             BSplineCurve3D (hdc, VL_3D, (LPCOORD) curve, 16);
  881.             SetViewerName (VL_CURRENT, "3D B-Spline Curve");
  882.             break;
  883.         case IDM_3DCURVE_NURBS:
  884.             PenColor (hdc, VL_GREEN);
  885.             Scale3D (5, 5, 5);
  886.             NURBSCurve3D (hdc, VL_2D, point, 8, Knot3);
  887.             SetViewerName (VL_CURRENT, "3D NURBS Curve");
  888.             break;
  889.         case IDM_3DCURVE_QBEZIER:
  890.         {
  891.             COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  892.             SetViewerName (VL_CURRENT, "3D Quadratic Bezier Curve");
  893.             Scale3D (12, 12, 12);
  894.             PenColor (hdc, VL_RED);
  895.             Polyline3D (hdc, VL_2D, point, 3);
  896.             PenColor (hdc, VL_BLUE);
  897.             PolyMark3D (hdc, VL_2D, point, 3, 3, 3, VL_DIAMONDMARK);
  898.             PenColor (hdc, VL_GREEN);
  899.             QBezierCurve3D (hdc, VL_2D, point);
  900.             SetViewerName (VL_CURRENT, "3D Quadratic Bezier Curve");
  901.             break;
  902.         }
  903.         case IDM_3DCURVE_QBSPLINE:
  904.         {
  905.             COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  906.             SetViewerName (VL_CURRENT, "3D Quadratic B-Spline Curve");
  907.             Scale3D (12, 12, 12);
  908.             PenColor (hdc, VL_RED);
  909.             Polyline3D (hdc, VL_2D, point, 8);
  910.             PenColor (hdc, VL_BLUE);
  911.             PolyMark3D (hdc, VL_2D, point, 8, 3, 3, VL_DIAMONDMARK);
  912.             PenColor (hdc, VL_GREEN);
  913.             QBSplineCurve3D (hdc, VL_2D, point, 8);
  914.             break;
  915.         }
  916.         case IDM_3DCURVE_QNURBS:
  917.         {
  918.             COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  919.             real knot[] = {0, 0, 0, 1, 1, 1, 1, 2, 3, 4, 5, 6};
  920.             
  921.             SetViewerName (VL_CURRENT, "3D Quadratic NURBS Curve");
  922.             Scale3D (12, 12, 12);
  923.             PenColor (hdc, VL_RED);
  924.             Polyline3D (hdc, VL_2D, point, 8);
  925.             PenColor (hdc, VL_BLUE);
  926.             PolyMark3D (hdc, VL_2D, point, 8, 3, 3, VL_DIAMONDMARK);
  927.             PenColor (hdc, VL_GREEN);
  928.             QNURBSCurve3D (hdc, VL_2D, point, 8, knot);
  929.             break;
  930.         }
  931.         case IDM_3DCURVE_CATMULLROM:
  932. //          CatmullRomSpline3D (hdc, cp3, n);
  933.             break;
  934.         case IDM_3DSHAPE_ELLIPSOID:
  935.             Ellipsoid (hdc, 20, 30, 40);
  936.             break;
  937.         case IDM_3DSHAPE_ELLIPTICPARAB:
  938. //          EllipticParaboloid (hdc, height, count1, count2);
  939.             break;
  940.         case IDM_3DSHAPE_HYPERBOLOID1:
  941. //          Hyperboloid1 (hdc, z1, z2, count1, count2);
  942.             break;
  943.         case IDM_3DSHAPE_HYPERBOLOID2:
  944. //          Hyperboloid2 (hdc, height, count1, count2);
  945.             break;
  946.         case IDM_3DSHAPE_HYPERBOLICPARAB:
  947. //          HyperbolicParaboloid (hdc, x1, x2, y1, y2, count1, count2);
  948.             break;
  949.     }
  950.     PopTransformation3D (NULL);
  951. }
  952.  
  953. VOIDED    ShowSolidPrimitives (HDC hdc, WORD cmd)
  954. {
  955.     ClearDepthBuffer (0xffff);
  956.     switch (cmd) {
  957.         case IDM_SOLID_TUBE:
  958.             SetViewerName (VL_CURRENT, "Tube and Ring");
  959.             Tube (hdc, 15, 20, 2, 30);
  960.             break;
  961.         case IDM_SOLID_TORUS:
  962.             SetViewerName (VL_CURRENT, "Torus and Wedged Torus");
  963.             TranslateTo3D (-20, 20, 0);
  964.             if (!Torus (hdc, 15, 5))
  965.                 break;
  966.             TranslateTo3D (20, -20, 0);
  967.             WedgedTorus (hdc, 15, 5, 90, 360, 180, 90);
  968.             break;
  969.         case IDM_SOLID_SPHERE:
  970.             SetViewerName (VL_CURRENT, "Sphere and Wedged Sphere");
  971.             WedgedSphere (hdc, 20, 20, 30, 90, 0, 45, 135);
  972.             break;
  973.         case IDM_SOLID_ELLIPSOID:
  974.             SetViewerName (VL_CURRENT, "Ellipsoid");
  975.             PenColor (hdc, VL_NONE);
  976.             Ellipsoid (hdc, 20, 40, 30);
  977.             break;
  978.         case IDM_SOLID_CYLINDER:
  979.             SetViewerName (VL_CURRENT, "Cylinder and Wedge");
  980.             if (!WedgedCylinder (hdc, 10, 20, 30, 0.7f, 90, 0))
  981.                 break;
  982.             TranslateTo3D (30, -30, 0);
  983.             if (!Wedge (hdc, 20, 10, 5, 45, 180))
  984.                 break;
  985.             TranslateTo3D (-30, 30, 0);
  986.             Wedge (hdc, 20, 10, 5, 180, 45);
  987.             break;
  988.         case IDM_SOLID_CONE:
  989.             SetViewerName (VL_CURRENT, "Cone and Wedged Cone");
  990.             if (!WedgedCone (hdc, 10, 20, 30, 90, 0))
  991.                 break;
  992.             TranslateTo3D (30, -30, 0);
  993.             if (!WedgedCone (hdc, 20, 10, 30, 110, 0))
  994.                 break;
  995.             TranslateTo3D (-30, 30, 0);
  996.             WedgedCone (hdc, 20, 10, 30, 180, 45);
  997.             break;
  998.         case IDM_SOLID_TETRAHEDRON:
  999.             SetViewerName (VL_CURRENT, "Tetrahedron (4 facets)");
  1000.             Tetrahedron (hdc, 20);
  1001.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_CROSSHAIR);
  1002.             break;
  1003.         case IDM_SOLID_OCTAHEDRON:
  1004.             SetViewerName (VL_CURRENT, "Octahedron (8 facets)");
  1005.             Octahedron (hdc, 20);
  1006.             MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  1007.             break;
  1008.         case IDM_SOLID_DODECAHEDRON:
  1009.             SetViewerName (VL_CURRENT, "Dodecahedron (12 facets)");
  1010.             Dodecahedron (hdc, 20);
  1011.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  1012.             break;
  1013.         case IDM_SOLID_ICOSAHEDRON:
  1014.             SetViewerName (VL_CURRENT, "Icosahedron (20 facets)");
  1015.             Icosahedron (hdc, 20);
  1016.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  1017.             break;
  1018.         case IDM_SOLID_FRUSTUM:
  1019.             SetViewerName (VL_CURRENT, "Frustum");
  1020.             Frustum (hdc, 20, 30, 10, 20, 20);
  1021.             break;
  1022.         case IDM_SOLID_RIDGE:
  1023.             SetViewerName (VL_CURRENT, "Ridge");
  1024.             Ridge (hdc, 20, 30, 10, 20);
  1025.             break;
  1026.         case IDM_SOLID_BOX:
  1027.             SetViewerName (VL_CURRENT, "Box");
  1028.             Cube (hdc, 40, 40, 20);
  1029.             break;
  1030.         case IDM_SOLID_STAR:
  1031.             SetViewerName (VL_CURRENT, "Solid Star");
  1032.             SolidStar (hdc, 5, 20, 20, 10);
  1033.             break;
  1034.         case IDM_SOLID_FLOWER:
  1035.             SetViewerName (VL_CURRENT, "Solid Flower");
  1036.             SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  1037.             break;
  1038.     }
  1039.     PenColor (hdc, VL_BLUE);
  1040.     DisplayViewerFrame (hdc, VL_CURRENT);
  1041.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1042.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1043. }
  1044.  
  1045. void    ShadingSettings (HWND hwnd, WORD cmd)
  1046. {
  1047.     COLORREF    color;
  1048.     FARPROC        lpProc;
  1049.  
  1050.     switch (cmd) {
  1051.         case IDM_OPTION_PREVIEW:
  1052.         {
  1053.             RECT rect = {50, 50, 100, 100};
  1054.             HDC    hdc;
  1055.  
  1056.             SelectViewer (viewer30);
  1057.             hdc = GetDC (hwnd);
  1058.             ShadingPreview (hdc, &rect, 40, 173);
  1059.             ReleaseDC (hwnd, hdc);
  1060.             break;
  1061.         }
  1062.         case IDM_GLOBAL_AMBIENT:
  1063.             color = ShadingColor (VL_CURRENT, VL_GLOBALAMBIENT, VL_INQUIRE);
  1064.             color = SelectColor (color);
  1065.             ShadingColor (VL_CURRENT, VL_GLOBALAMBIENT, color);
  1066.             break;
  1067.         case IDM_OPTION_BACKCOLOR:
  1068.         {
  1069.             HBRUSH    hbrush;
  1070.  
  1071.             backcolor = SelectColor (backcolor);
  1072.             hbrush = GetClassWord (hwnd, GCW_HBRBACKGROUND);
  1073.             DeleteObject (hbrush);
  1074.             hbrush = CreateSolidBrush (backcolor);
  1075.             SetClassWord (hwnd, GCW_HBRBACKGROUND, hbrush);
  1076.             InvalidateRect (hwnd, NULL, TRUE);
  1077.             UpdateWindow (hwnd);
  1078.             break;
  1079.         }
  1080.         case IDM_OPTION_REDRAW:
  1081.             InvalidateRect (hwnd, NULL, TRUE);
  1082.             UpdateWindow (hwnd);
  1083.             break;
  1084.         case IDM_OPTION_SHADEMODE:
  1085.              lpProc = MakeProcInstance (DlgShading, hInst);
  1086.             DialogBox (hInst, "DLGSHADING", hwnd, lpProc);
  1087.             FreeProcInstance (lpProc);
  1088.             break;
  1089.         case IDM_SELECT_M1:
  1090.             SelectMaterial (mater0);
  1091.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1092.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1093.             FreeProcInstance (lpProc);
  1094.             break;
  1095.         case IDM_SELECT_M2:
  1096.             SelectMaterial (mater1);
  1097.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1098.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1099.             FreeProcInstance (lpProc);
  1100.             break;
  1101.         case IDM_SELECT_M3:
  1102.             SelectMaterial (mater2);
  1103.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1104.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1105.             FreeProcInstance (lpProc);
  1106.             break;
  1107.         case IDM_SELECT_M4:
  1108.             SelectMaterial (mater3);
  1109.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1110.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1111.             FreeProcInstance (lpProc);
  1112.             break;
  1113.         case IDM_SELECT_L1:
  1114.             SelectLight (light0);
  1115.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1116.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1117.             FreeProcInstance (lpProc);
  1118.             break;
  1119.         case IDM_SELECT_L2:
  1120.             SelectLight (light1);
  1121.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1122.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1123.             FreeProcInstance (lpProc);
  1124.             break;
  1125.         case IDM_SELECT_L3:
  1126.             SelectLight (light2);
  1127.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1128.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1129.             FreeProcInstance (lpProc);
  1130.             break;
  1131.         case IDM_SELECT_L4:
  1132.             SelectLight (light3);
  1133.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1134.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1135.             FreeProcInstance (lpProc);
  1136.             break;
  1137.         case IDM_OPTION_TEXTURE:
  1138.             lpProc = MakeProcInstance (DlgTexture, hInst);
  1139.             DialogBox (hInst, "DLGTEXTURE", hwnd, lpProc);
  1140.             FreeProcInstance (lpProc);
  1141.             break;
  1142.     }
  1143. }
  1144.  
  1145. WORD    halign = TA_CENTER;
  1146. WORD    valign = TA_BASELINE;
  1147.  
  1148. VOIDED    ShowTextPrimitives (HDC hdc, int func)
  1149. {
  1150.     char    str[40];
  1151.  
  1152.     wsprintf (str, "Visualib\nAdvanced\nTechnology");
  1153.     switch (func) {
  1154.         case IDM_TEXT_2D:
  1155.             SelectViewer (viewer20);
  1156.             TextParameter (VL_TEXT_HEIGHT, 4);
  1157.             BrushColor (hdc, VL_RED);
  1158.             PenColor (hdc, VL_GREEN);
  1159.             SetTextAlign (hdc, halign | valign);
  1160.             Text2D (hdc, 0, 0, 0, str);
  1161.             SetViewerName (VL_CURRENT, "2D Horizontal Text");
  1162.             break;
  1163.         case IDM_TEXT_3D:
  1164.             SelectViewer (viewer30);
  1165.             MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1166.             PushTransformation3D (NULL);
  1167.             TextParameter (VL_TEXT_HEIGHT, 15);
  1168.             BrushColor (hdc, VL_YELLOW);
  1169.             PenColor (hdc, VL_BLUE);
  1170.             SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1171.             Text3D (hdc, 3, 1, 0, str);
  1172.             PushTransformation3D (NULL);
  1173.             Rotate3D (90, 'y');
  1174.             SetTextAlign (hdc, TA_RIGHT | TA_BOTTOM);
  1175.             Text3D (hdc, -3, 1, 0, str);
  1176.             PopTransformation3D (NULL);
  1177.             Rotate3D (-90, 'x');
  1178.             SetTextAlign (hdc, TA_TOP | TA_LEFT);
  1179.             Text3D (hdc, 3, -1, 0, str);
  1180.             PopTransformation3D (NULL);
  1181.             SetViewerName (VL_CURRENT, "3D Horizontal Text");
  1182.             break;
  1183.         case IDM_TEXT_SOLID:
  1184.             SelectViewer (viewer30);
  1185.             TextParameter (VL_TEXT_HEIGHT, 30);
  1186.             ClearDepthBuffer (0xffff);
  1187.             TextParameter (VL_TEXT_THICKNESS, 8);
  1188.             SelectMaterial (mater0);
  1189.             PushTransformation3D (NULL);
  1190.             Rotate3D (135, 'z');
  1191.             Rotate3D (30, 'x');
  1192.             SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1193.             SolidText (hdc, str);
  1194.             PopTransformation3D (NULL);
  1195.             SetViewerName (VL_CURRENT, "Solid Text");
  1196.             break;
  1197.     }
  1198.     PenColor (hdc, VL_BLUE);
  1199.     DisplayViewerFrame (hdc, VL_CURRENT);
  1200.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1201.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1202. }
  1203.  
  1204. void    ProcessWindowPaint (HWND hwnd)
  1205. {
  1206.     PAINTSTRUCT ps;
  1207.     HDC         hdc;
  1208.  
  1209.     hdc = BeginPaint (hwnd, &ps);
  1210.     SelectPalette (hdc, hpal, 0);
  1211.     RealizePalette (hdc);
  1212.     FunctionDemos (hdc);
  1213.     EndPaint (hwnd, &ps);
  1214. }
  1215.  
  1216. void    SpotlightDemo (HDC hdc)
  1217. {
  1218.     SelectViewer (viewer30);
  1219.     PenColor (hdc, VL_BLUE);
  1220.     DisplayViewerFrame (hdc, VL_CURRENT);
  1221.     SetViewerName (VL_CURRENT, "Spot Lights Demo");
  1222.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1223.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1224.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  1225.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  1226.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1227.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_PHONGSHADE);
  1228.     ClearDepthBuffer (0xffff);
  1229.     SelectMaterial (mater0);
  1230.     SwitchLight (light4, TRUE);
  1231.     SwitchLight (light5, TRUE);
  1232.     SwitchLight (light6, TRUE);
  1233.     SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  1234. }
  1235.  
  1236. void    ImageMappingDemo (HDC hdc)
  1237. {
  1238.     COORD    point[12];
  1239.     static BOOL    LoadImage = TRUE;
  1240.  
  1241.     if (LoadImage) {
  1242. //        ReadDIBFile ("redmarbl.bmp", &hdib1);
  1243.         ReadDIBFile (NULL, &hdib1);
  1244.         ReadDIBFile ("deer256.bmp", &hdib2);
  1245.         ReadDIBFile ("c:\\windows\\system\\vgalogo.rle", &hdib3);
  1246.         LoadImage = FALSE;
  1247.     }
  1248.  
  1249.     SelectViewer (viewer30);
  1250.     SetViewerName (VL_CURRENT, "Image Mapping");
  1251.     PenColor (hdc, VL_BLUE);
  1252.     DisplayViewerFrame (hdc, VL_CURRENT);
  1253.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1254.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1255.     Scale3D (20, 20, 30);
  1256.  
  1257.     point[0] = -1; point[1] = -1; point[2] = 1;
  1258.     point[3] = 1; point[4] = -1; point[5] = 1;
  1259.     point[6] = 1; point[7] = 1; point[8] = 1;
  1260.     point[9] = -1; point[10] = 1; point[11] = 1;
  1261.     if (hdib1) {
  1262.         if (!ImageMap3D (hdc, hdib1, VL_3D, point))
  1263.             return;
  1264.     }
  1265.  
  1266.     point[0] = 1; point[1] = 1; point[2] = 1;
  1267.     point[3] = 1; point[4] = 1; point[5] = -1;
  1268.     point[6] = -1; point[7] = 1; point[8] = -1;
  1269.     point[9] = -1; point[10] = 1; point[11] = 1;
  1270.     if (hdib2) {
  1271.         if (!ImageMap3D (hdc, hdib2, VL_3D, point))
  1272.             return;
  1273.     }
  1274.  
  1275.     point[0] = 1; point[1] = -1; point[2] = -1;
  1276.     point[3] = 1; point[4] = 1; point[5] = -1;
  1277.     point[6] = 1; point[7] = 1; point[8] = 1;
  1278.     point[9] = 1; point[10] = -1; point[11] = 1;
  1279.     if (hdib3) {
  1280.         ImageMap3D (hdc, hdib3, VL_3D, point);
  1281.     }
  1282. }
  1283.  
  1284. void    TranslateTransf2D (HDC hdc)
  1285. {
  1286.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1287.     SetViewerName (VL_CURRENT, "2D Translate Transformation");
  1288.     BrushColor (hdc, VL_RED);
  1289.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1290.     Label2D (hdc, 0, 0, "Original");
  1291.     TranslateTo2D (5, 3);
  1292.     BrushColor (hdc, VL_GREEN);
  1293.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1294.     Label2D (hdc, 0, 0, "Translated To (5,3)");
  1295.     PushTransformation2D (NULL);
  1296.     Translate2D (0, -6);
  1297.     BrushColor (hdc, VL_YELLOW);
  1298.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1299.     Label2D (hdc, 0, 0, "Translated (0,-6) from above");
  1300.     PopTransformation2D (NULL);
  1301.     Translate2D (-10, 0);
  1302.     BrushColor (hdc, VL_BLUE);
  1303.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1304.     Label2D (hdc, 0, 0, "Translated (-10,0) from right");
  1305.     Translate2D (0, -6);
  1306.     BrushColor (hdc, VL_WHITE);
  1307.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1308.     Label2D (hdc, 0, 0, "Translated (0,-6) from above");
  1309. }
  1310.  
  1311. void    MirrorTransf2D (HDC hdc)
  1312. {
  1313.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1314.     SetViewerName (VL_CURRENT, "2D Mirror Transformation");
  1315.     BrushColor (hdc, VL_RED);
  1316.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1317.     Label2D (hdc, 5, 3, "Original");
  1318.     PushTransformation2D (NULL);
  1319.     Mirror2D (0, 0, 0);
  1320.     BrushColor (hdc, VL_GREEN);
  1321.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1322.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with 0 degree");
  1323.     PopTransformation2D (NULL);
  1324.     PushTransformation2D (NULL);
  1325.     Mirror2D (0, 0, 90);
  1326.     BrushColor (hdc, VL_YELLOW);
  1327.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1328.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with 90 degree");
  1329.     PopTransformation2D (NULL);
  1330.     PushTransformation2D (NULL);
  1331.     Mirror2D (0, 0, (real)(atan2 (-5, 3) * RTOD));
  1332.     BrushColor (hdc, VL_BLUE);
  1333.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1334.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with radian (-5,3)");
  1335.     PopTransformation2D (NULL);
  1336. }
  1337.  
  1338. void    StretchTransf2D (HDC hdc)
  1339. {
  1340.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1341.     SetViewerName (VL_CURRENT, "2D Stretch Transformation");
  1342.     BrushColor (hdc, VL_RED);
  1343.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1344.     Label2D (hdc, 0, 0, "Original");
  1345.     PushTransformation2D (NULL);
  1346.     Stretch2D (5, 3, 0, 1.5f);
  1347.     BrushColor (hdc, VL_GREEN);
  1348.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1349.     Label2D (hdc, 5, 3, "Stretched along 0 degree");
  1350.     PopTransformation2D (NULL);
  1351.     PushTransformation2D (NULL);
  1352.     Stretch2D (5, -3, 90, 1.5f);
  1353.     BrushColor (hdc, VL_YELLOW);
  1354.     Star2D (hdc, 5, -3, 0, 2, 2, 5);
  1355.     Label2D (hdc, 5, -3, "Stretched along 90 degree");
  1356.     PopTransformation2D (NULL);
  1357.     PushTransformation2D (NULL);
  1358.     Stretch2D (-5, -3, 45, 1.5f);
  1359.     BrushColor (hdc, VL_BLUE);
  1360.     Star2D (hdc, -5, -3, 0, 2, 2, 5);
  1361.     Label2D (hdc, -5, -3, "Stretched along 45 degree");
  1362.     PopTransformation2D (NULL);
  1363.     PushTransformation2D (NULL);
  1364.     Stretch2D (-5, 3, 45, -1.5f);
  1365.     BrushColor (hdc, VL_BROWN);
  1366.     Star2D (hdc, -5, 3, 0, 2, 2, 5);
  1367.     Label2D (hdc, -5, 3, "Stretched and flipped 45 degree");
  1368.     PopTransformation2D (NULL);
  1369. }
  1370.  
  1371. void    ShearTransf2D (HDC hdc)
  1372. {
  1373.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1374.     SetViewerName (VL_CURRENT, "2D Shear Transformation");
  1375.     BrushColor (hdc, VL_RED);
  1376.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1377.     Label2D (hdc, 0, 0, "Original");
  1378.     PushTransformation2D (NULL);
  1379.     Shear2D (5, 3, 0, 0.5f, 0);
  1380.     BrushColor (hdc, VL_GREEN);
  1381.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1382.     Label2D (hdc, 5, 3, "Horizontal shear");
  1383.     PopTransformation2D (NULL);
  1384.     PushTransformation2D (NULL);
  1385.     Shear2D (5, -3, 0, 0, 0.5f);
  1386.     BrushColor (hdc, VL_BLUE);
  1387.     Star2D (hdc, 5, -3, 0, 2, 2, 5);
  1388.     Label2D (hdc, 5, -3, "Vertical shear");
  1389.     PopTransformation2D (NULL);
  1390.     PushTransformation2D (NULL);
  1391.     Shear2D (-5, -3, 0, 0.5f, 0.5f);
  1392.     BrushColor (hdc, VL_YELLOW);
  1393.     Star2D (hdc, -5, -3, 0, 2, 2, 5);
  1394.     Label2D (hdc, -5, -3, "Horizontal and vertical shear");
  1395.     PopTransformation2D (NULL);
  1396.     PushTransformation2D (NULL);
  1397.     Shear2D (-5, 3, 45, 0.5f, 0);
  1398.     BrushColor (hdc, VL_BROWN);
  1399.     Star2D (hdc, -5, 3, 0, 2, 2, 5);
  1400.     Label2D (hdc, -5, 3, "Horizontal shear along 45 degree");
  1401.     PopTransformation2D (NULL);
  1402. }
  1403.  
  1404. void    PointRotateTransf2D (HDC hdc)
  1405. {
  1406.     SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
  1407.     Label2D (hdc, 5, 3, "(5,3)");
  1408.     SetTextAlign (hdc, TA_RIGHT | TA_BASELINE);
  1409.     Label2D (hdc, -5, 3, "(-5,3)");
  1410.     SetTextAlign (hdc, TA_CENTER | TA_TOP);
  1411.     Label2D (hdc, -5, -3, "(-5,-3)");
  1412.     SetTextAlign (hdc, TA_LEFT | TA_BASELINE);
  1413.     Label2D (hdc, 5, -3, "(5,-3)");
  1414.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1415.     SetViewerName (VL_CURRENT, "2D Point Ratate Transformation");
  1416.     PenColor (hdc, VL_WHITE);
  1417.     BrushColor (hdc, VL_RED);
  1418.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1419.     Label2D (hdc, 0, 0, "Original");
  1420.     Line2D (hdc, 5, 3, 0, 0);
  1421.     PushTransformation2D (NULL);
  1422.     PointRotate2D (5, 3, 90);
  1423.     BrushColor (hdc, VL_GREEN);
  1424.     Label2D (hdc, 0, 0, "Rotate 90 degree around (5,3)");
  1425.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1426.     LineTo2D (hdc, 0, 0);
  1427.     LineTo2D (hdc, 5, 3);
  1428.      PopTransformation2D (NULL);
  1429.     Line2D (hdc, -5, 3, 0, 0);
  1430.     PushTransformation2D (NULL);
  1431.     PointRotate2D (-5, 3, 45);
  1432.     BrushColor (hdc, VL_YELLOW);
  1433.     Label2D (hdc, 0, 0, "Rotate 45 degree around (-5,3)");
  1434.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1435.     LineTo2D (hdc, 0, 0);
  1436.     LineTo2D (hdc, -5, 3);
  1437.     PopTransformation2D (NULL);
  1438.     Line2D (hdc, 5, -3, 0, 0);
  1439.     PushTransformation2D (NULL);
  1440.     PointRotate2D (5, -3, 45);
  1441.     BrushColor (hdc, VL_BLUE);
  1442.     Label2D (hdc, 0, 0, "Rotate 45 degree around (5,-3)");
  1443.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1444.     LineTo2D (hdc, 0, 0);
  1445.     LineTo2D (hdc, 5, -3);
  1446.     PopTransformation2D (NULL);
  1447.     Line2D (hdc, -5, -3, 0, 0);
  1448.     PushTransformation2D (NULL);
  1449.     PointRotate2D (-5, -3, 90);
  1450.     BrushColor (hdc, VL_BROWN);
  1451.     Label2D (hdc, 0, 0, "Rotate 90 degree around (-5,-3)");
  1452.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1453.     LineTo2D (hdc, 0, 0);
  1454.     LineTo2D (hdc, -5, -3);
  1455.     PopTransformation2D (NULL);
  1456. }
  1457.  
  1458. void    PointScaleTransf2D (HDC hdc)
  1459. {
  1460.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1461.     BrushColor (hdc, VL_RED);
  1462.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1463.     Label2D (hdc, 5, 3, "Original");
  1464.     PushTransformation2D (NULL);
  1465.     PointScale2D (0, 0, -1, 1);
  1466.     BrushColor (hdc, VL_GREEN);
  1467.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1468.     Label2D (hdc, 5, 3, "Horizontal flipped");
  1469.     PopTransformation2D (NULL);
  1470.     PushTransformation2D (NULL);
  1471.     PointScale2D (0, 0, 1, -1);
  1472.     BrushColor (hdc, VL_BLUE);
  1473.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1474.     Label2D (hdc, 5, 3, "Vertical flipped");
  1475.     PopTransformation2D (NULL);
  1476.     PushTransformation2D (NULL);
  1477.     PointScale2D (0, 0, -1, -1);
  1478.     BrushColor (hdc, VL_YELLOW);
  1479.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1480.     Label2D (hdc, 5, 3, "Horizontal and vertical flipped");
  1481.     PopTransformation2D (NULL);
  1482. }
  1483.     
  1484. void    Transformation2D (HDC hdc, int func)
  1485. {
  1486.     SetROP2 (hdc, R2_XORPEN);
  1487.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1488.     PushTransformation2D (NULL);
  1489.     switch (func) {
  1490.         case IDM_2DTRANSF_TRANSLATE:
  1491.             TranslateTransf2D (hdc);
  1492.             break;
  1493.         case IDM_2DTRANSF_SCALE:
  1494.             break;
  1495.         case IDM_2DTRANSF_POINTSCALE:
  1496.             PointScaleTransf2D (hdc);
  1497.             break;
  1498.         case IDM_2DTRANSF_ROTATE:
  1499.             break;
  1500.         case IDM_2DTRANSF_POINTROTATE:
  1501.             PointRotateTransf2D (hdc);
  1502.             break;
  1503.         case IDM_2DTRANSF_STRETCH:
  1504.             StretchTransf2D (hdc);
  1505.             break;
  1506.         case IDM_2DTRANSF_SHEAR:
  1507.             ShearTransf2D (hdc);
  1508.             break;
  1509.         case IDM_2DTRANSF_MIRROR:
  1510.             MirrorTransf2D (hdc);
  1511.             break;
  1512.     }
  1513.     PopTransformation2D (NULL);
  1514.     PenColor (hdc, VL_BLUE);
  1515.     DisplayViewerFrame (hdc, VL_CURRENT);
  1516.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1517.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1518. }
  1519.  
  1520. void    AxleRotateTransf3D (HDC hdc)
  1521. {
  1522.     short    i;
  1523.     VECTOR3    ref = {0, 0, 0}, dir;
  1524.     char    str[] = "Visualib";
  1525.  
  1526.     SetTextAlign(hdc, TA_LEFT | TA_BOTTOM);
  1527.     TextParameter (VL_TEXT_HEIGHT, 20);
  1528.     MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  1529.     BrushColor (hdc, VL_RED);
  1530.     Text3D (hdc, 15, 15, 0, str);
  1531.     VSET3 (dir, 1, 0, 0);
  1532.     for (i = 1; i < 4; i++) {
  1533.         PushTransformation3D (NULL);
  1534.         AxleRotate3D (ref, dir, i * 90);
  1535.         BrushColor (hdc, i+1);
  1536.         Text3D (hdc, 15, 15, 0, str);
  1537.         PopTransformation3D (NULL);
  1538.     }
  1539.     VSET3 (dir, 0, 1, 0);
  1540.     for (i = 1; i < 4; i++) {
  1541.         PushTransformation3D (NULL);
  1542.         AxleRotate3D (ref, dir, i * 90);
  1543.         BrushColor (hdc, i+4);
  1544.         Text3D (hdc, 15, 15, 0, str);
  1545.         PopTransformation3D (NULL);
  1546.     }
  1547.     VSET3 (dir, 1, -1, 0);
  1548.     for (i = 1; i < 4; i++) {
  1549.         PushTransformation3D (NULL);
  1550.         AxleRotate3D (ref, dir, i * 90);
  1551.         BrushColor (hdc, i+7);
  1552.         Text3D (hdc, 15, 15, 0, str);
  1553.         PopTransformation3D (NULL);
  1554.     }
  1555. }
  1556.  
  1557. void    StretchTransf3D (HDC hdc)
  1558. {
  1559.     VECTOR3    ref = {0, 0, 0}, dir;
  1560.  
  1561.     TextParameter (VL_TEXT_HEIGHT, 30);
  1562.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1563.     PushTransformation3D (NULL);
  1564.     VSET3 (dir, -1, 1, 1);
  1565.     Stretch3D (ref, dir, 1.5f);
  1566.     Cube (hdc, 20, 20, 20);
  1567.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1568.     PopTransformation3D (NULL);
  1569. }
  1570.  
  1571. void    ShearTransf3D (HDC hdc)
  1572. {
  1573.     VECTOR3    origin = {0, 0, 0}, normal = {0, 0, 1};
  1574.  
  1575.     TextParameter (VL_TEXT_HEIGHT, 30);
  1576.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1577.     PushTransformation3D (NULL);
  1578.     Shear3D (origin, normal, -0.5f, 0.5f);
  1579.     Cube (hdc, 20, 20, 20);
  1580.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1581.     PopTransformation3D (NULL);
  1582. }
  1583.  
  1584. void    MirrorTransf3D (HDC hdc)
  1585. {
  1586.     VECTOR3    ref = {0, 0, 0}, dir;
  1587.     char    str[] = "Visualib";
  1588.  
  1589.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1590.     SetViewerName (VL_CURRENT, "3D Mirror Transformation");
  1591.     SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1592.     TextParameter (VL_TEXT_HEIGHT, 20);
  1593.     BrushColor (hdc, VL_RED);
  1594.     Text3D (hdc, 3, 3, 0, str);
  1595.     PushTransformation3D (NULL);
  1596.     VSET3 (dir, 1, 0, 0);
  1597.     Mirror3D (ref, dir);
  1598.     BrushColor (hdc, VL_GREEN);
  1599.     Text3D (hdc, 3, 3, 0, str);
  1600.     PopTransformation3D (NULL);
  1601.     PushTransformation3D (NULL);
  1602.     VSET3 (dir, 0, 1, 0);
  1603.     Mirror3D (ref, dir);
  1604.     BrushColor (hdc, VL_YELLOW);
  1605.     Text3D (hdc, 3, 3, 0, str);
  1606.     PopTransformation3D (NULL);
  1607.     PushTransformation3D (NULL);
  1608.     VSET3 (dir, -1, -1, 0);
  1609.     Mirror3D (ref, dir);
  1610.     BrushColor (hdc, VL_BLUE);
  1611.     Text3D (hdc, 3, 3, 0, str);
  1612.     PopTransformation3D (NULL);
  1613. }
  1614.  
  1615. void    PointScaleTransf3D (HDC hdc)
  1616. {
  1617.     char    str[] = "Visualib";
  1618.  
  1619.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1620.     SetViewerName (VL_CURRENT, "3D PointScale Transformation");
  1621.     SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1622.     TextParameter (VL_TEXT_HEIGHT, 20);
  1623.     BrushColor (hdc, VL_RED);
  1624.     Text3D (hdc, 3, 3, 0, str);
  1625.     PushTransformation3D (NULL);
  1626.     PointScale3D (0, 0, 0, -1, 1, 1);
  1627.     BrushColor (hdc, VL_GREEN);
  1628.     Text3D (hdc, 3, 3, 0, str);
  1629.     PopTransformation3D (NULL);
  1630.     PushTransformation3D (NULL);
  1631.     PointScale3D (0, 0, 0, 1, -1, 1);
  1632.     BrushColor (hdc, VL_YELLOW);
  1633.     Text3D (hdc, 3, 3, 0, str);
  1634.     PopTransformation3D (NULL);
  1635.     PushTransformation3D (NULL);
  1636.     PointScale3D (0, 0, 0, -1, -1, 1);
  1637.     BrushColor (hdc, VL_BLUE);
  1638.     Text3D (hdc, 3, 3, 0, str);
  1639.     PopTransformation3D (NULL);
  1640. }
  1641.  
  1642. void    Transformation3D (HDC hdc, int func)
  1643. {
  1644.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1645.     ClearDepthBuffer (0xffff);
  1646.     switch (func) {
  1647.         case IDM_3DTRANSF_TRANSLATE:
  1648.             break;
  1649.         case IDM_3DTRANSF_SCALE:
  1650.             break;
  1651.         case IDM_3DTRANSF_POINTSCALE:
  1652.             PointScaleTransf3D (hdc);
  1653.             break;
  1654.         case IDM_3DTRANSF_ROTATE:
  1655.             break;
  1656.         case IDM_3DTRANSF_AXLEROTATE:
  1657.             AxleRotateTransf3D (hdc);
  1658.             break;
  1659.         case IDM_3DTRANSF_STRETCH:
  1660.             StretchTransf3D (hdc);
  1661.             break;
  1662.         case IDM_3DTRANSF_SHEAR:
  1663.             ShearTransf3D (hdc);
  1664.             break;
  1665.         case IDM_3DTRANSF_MIRROR:
  1666.             MirrorTransf3D (hdc);
  1667.             break;
  1668.     }
  1669.     PenColor (hdc, VL_BLUE);
  1670.     DisplayViewerFrame (hdc, VL_CURRENT);
  1671.     TextColor (hdc, VL_RED, VL_BLACK, TRANSPARENT);
  1672.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1673. }
  1674.  
  1675. VOIDED    MaterialPropertyDemo (HDC hdc)
  1676. {
  1677.     short    i, j, n = 1;
  1678.     real    ks, kd, orgks, orgkd, orgn;
  1679.     RECT    rect;
  1680.  
  1681.     SwitchLight (light7, TRUE);
  1682.     SwitchLight (light8, TRUE);
  1683.     SelectViewer (viewer30);
  1684.     SetViewerName (VL_CURRENT, "Material Reflection Property");
  1685.     PenColor (hdc, VL_BLUE);
  1686.     DisplayViewerFrame (hdc, VL_CURRENT);
  1687.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1688.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1689.     orgks = ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, VL_INQUIRE);
  1690.     orgkd = ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, VL_INQUIRE);
  1691.     orgn = ShadingFactor (VL_CURRENT, VL_SHININESS, VL_INQUIRE);
  1692.     rect.top = 10;
  1693.     ks = 0;
  1694.     for (i = 0; i < 6; i++) {
  1695.         kd = 0;
  1696.         rect.left = 10;
  1697.         rect.bottom = rect.top + 40;
  1698.         for (j = 0; j < 10; j++) {
  1699.             rect.right = rect.left + 40;
  1700.             ShadingFactor (VL_CURRENT, VL_SHININESS, n);
  1701.             ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, ks);
  1702.             ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, kd);
  1703.             if (!ShadingPreview (hdc, &rect, 5, 173))
  1704.                 goto exit;
  1705.             rect.left += 49;
  1706.             kd += 0.1f;
  1707.         }
  1708.         ks += 0.2f;
  1709.         rect.top += 53;
  1710.         n *= 2;
  1711.     }
  1712. exit:
  1713.     ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, orgkd);
  1714.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, orgks);
  1715.     ShadingFactor (VL_CURRENT, VL_SHININESS, orgn);
  1716. }
  1717.  
  1718. void    CompositeDemo3D (HDC hdc)
  1719. {
  1720.     real    r0, r1, r2, t1, t2, h;
  1721.     short    i;
  1722.     BOOL    zbuf, flag;
  1723.  
  1724.     SelectViewer (viewer30);
  1725.     SetViewerName (VL_CURRENT, "Object Composition");
  1726.     PenColor (hdc, VL_WHITE);
  1727.     DisplayViewerFrame (hdc, VL_CURRENT);
  1728.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1729.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1730.     zbuf = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1731.     ClearDepthBuffer (0xffff);
  1732.     SwitchLight (light7, TRUE);
  1733. //    SwitchLight (light8, TRUE);
  1734.     SelectMaterial (mater0);
  1735.     PushTransformation3D (NULL);
  1736.     r0 = 4.5f; r1 = 30; r2 = 40;
  1737.     h = 10;
  1738.     t1 = 3, t2 = 2;
  1739.     if (!Tube (hdc, r1, r1, t1, h))
  1740.         goto exit;
  1741.  
  1742.     if (!Ring (hdc, r2, r2, t2, h, 90, 360, 1))
  1743.         goto exit;
  1744.     h *= 0.5f;
  1745.     Translate3D (0, 0, h);
  1746.     SelectMaterial (mater1);
  1747.     for (i = 0; i < 18; i++) {
  1748.         Rotate3D (20, 'z');
  1749.         PushTransformation3D (NULL);
  1750.         Translate3D (35, 0, 0);
  1751.         flag = Sphere (hdc, r0);
  1752.         PopTransformation3D (NULL);
  1753.         if (!flag)
  1754.             break;
  1755.     }
  1756. exit:
  1757.     PopTransformation3D (NULL);
  1758.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, zbuf);
  1759. }
  1760.  
  1761. void    DepthClippingDemo (HDC hdc)
  1762. {
  1763.     SelectViewer (viewer30);
  1764.     SetViewerName (VL_CURRENT, "Depth Buffer and Clipping");
  1765.     TextColor (hdc, VL_YELLOW, VL_BLACK, TRANSPARENT);
  1766.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1767.     PenColor (hdc, VL_YELLOW);
  1768.     DisplayViewerFrame (hdc, VL_CURRENT);
  1769.     SetPerspective (VL_CURRENT, 45, 1, 141, 200);
  1770.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1771.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_PHONGSHADE);
  1772.     ClearDepthBuffer (0xffff);
  1773. //    SwitchLight (light7, TRUE);
  1774.     SwitchLight (light8, TRUE);
  1775.     SelectMaterial (mater1);
  1776.     TranslateTo3D (20, 0, 0);
  1777.     if (!Sphere (hdc, 20))
  1778.         goto exit;
  1779.     SelectMaterial (mater2);
  1780.     TranslateTo3D (0, 20, 0);
  1781.     if (!Sphere (hdc, 20))
  1782.         goto exit;
  1783.     SelectMaterial (mater3);
  1784.     TranslateTo3D (0, 0, 20);
  1785.     if (!Sphere (hdc, 20))
  1786.         return;
  1787.     TranslateTo3D (0, 0, 0);
  1788.     SelectMaterial (mater0);
  1789.     if (!Cube (hdc, 40, 40, 40))
  1790.         goto exit;
  1791.  exit:
  1792.     SetPerspective (VL_CURRENT, 45, 1, 30, 1000);
  1793. }
  1794.  
  1795. void    MarbleRingDemo (hdc)
  1796. {
  1797.     BOOL    depthbuffer;
  1798.     short    texture;
  1799.  
  1800.     SelectViewer (viewer30);
  1801.     SetViewerName (VL_CURRENT, "Marble Ring");
  1802.     TextColor (hdc, VL_BROWN, VL_BLACK, TRANSPARENT);
  1803.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1804.     PenColor (hdc, VL_BROWN);
  1805.     DisplayViewerFrame (hdc, VL_CURRENT);
  1806.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1807.     ClearDepthBuffer (0xffff);
  1808.     texture = SolidTexture (VL_MARBLE);
  1809.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1810.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1811.     SwitchLight (light7, TRUE);
  1812.     SwitchLight (light8, TRUE);
  1813.     Torus (hdc, 35, 10);
  1814.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1815.     SolidTexture (texture);
  1816. }
  1817.  
  1818. void    WoodSurfaceDemo (HDC hdc)
  1819. {
  1820.     BOOL    depthbuffer;
  1821.     short    texture;
  1822.     
  1823.     POINT3D surf[36] = {
  1824.         {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  1825.         {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  1826.         {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  1827.         {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  1828.         {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  1829.         {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  1830.     real    sknot[20] = {0,0,0,1,2,3,3,3};
  1831.     real    tknot[20] = {0,0,0,1,2,3,3,3};
  1832.  
  1833.     SelectViewer (viewer30);
  1834.     SetViewerName (VL_CURRENT, "Wood Surface");
  1835.     TextColor (hdc, VL_GREEN, VL_BLACK, TRANSPARENT);
  1836.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1837.     PenColor (hdc, VL_GREEN);
  1838.     DisplayViewerFrame (hdc, VL_CURRENT);
  1839.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1840.     ClearDepthBuffer (0xffff);
  1841.     texture = SolidTexture (VL_WOODGRAIN);
  1842.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1843.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1844.     SwitchLight (light7, TRUE);
  1845.     SwitchLight (light8, TRUE);
  1846.     Translate3D (-15, -15, 5);
  1847.     Scale3D (10, 10, 5);
  1848.     NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 6, 6, sknot, tknot, 4, 4);
  1849.     SolidTexture (texture);
  1850.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1851. }
  1852.  
  1853. void    GraniteCubeDemo (HDC hdc)
  1854. {
  1855.     BOOL    depthbuffer;
  1856.     real    l7, l8;
  1857.     short    texture;
  1858.  
  1859.     SelectViewer (viewer30);
  1860.     SetViewerName (VL_CURRENT, "Granite Cube");
  1861.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1862.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1863.     PenColor (hdc, VL_WHITE);
  1864.     DisplayViewerFrame (hdc, VL_CURRENT);
  1865.     ClearDepthBuffer (0xffff);
  1866.     texture = SolidTexture (VL_GRANITE);
  1867.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1868.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1869.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1870.     l7 = ShadingFactor (light7, VL_LIGHTINTENSITY, 2);
  1871.     l8 = ShadingFactor (light8, VL_LIGHTINTENSITY, 2);
  1872.     SwitchLight (light7, TRUE);
  1873.     SwitchLight (light8, TRUE);
  1874.     Cube (hdc, 30, 30, 30);
  1875.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1876.     SolidTexture (texture);
  1877.     ShadingFactor (light7, VL_LIGHTINTENSITY, l7);
  1878.     ShadingFactor (light8, VL_LIGHTINTENSITY, l8);
  1879. }
  1880.  
  1881. void    StereoTextDemo (HDC hdc)
  1882. {
  1883.     BOOL    depthbuffer;
  1884.  
  1885.     if (!SelectFont ())
  1886.         return;
  1887.     SelectViewer (viewer30);
  1888.     SetViewerName (VL_CURRENT, "Stereo Text");
  1889.     PenColor (hdc, VL_BLUE);
  1890.     DisplayViewerFrame (hdc, VL_CURRENT);
  1891.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1892.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1893.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1894.     ClearDepthBuffer (0xffff);
  1895.     TextParameter (VL_TEXT_HEIGHT, 40);
  1896.     TextParameter (VL_TEXT_THICKNESS, 8);
  1897.     SwitchLight (light4, TRUE);
  1898.     SwitchLight (light7, TRUE);
  1899.     SelectMaterial (mater0);
  1900.     PushTransformation3D (NULL);
  1901.     Rotate3D (135, 'z');
  1902.     Rotate3D (90, 'x');
  1903.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1904.     SolidText (hdc, "Visualib");
  1905.     PopTransformation3D (NULL);
  1906.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1907. }
  1908.  
  1909. void    AnimationDemo (HDC hdc, WORD cmd)
  1910. {
  1911.     switch (cmd) {
  1912.         case IDM_ANIMATE_FRAME:
  1913.             animate_length = 10;
  1914.             RotateFrame (hdc);
  1915.             break;
  1916.         case IDM_ANIMATE_OBJECT2D:
  1917.             animate_length = 10;
  1918.             ObjectMotion2D (hdc);
  1919.             break;
  1920.         case IDM_ANIMATE_SURFACE:
  1921.             animate_length = 10;
  1922.             RotateSurface (hdc);
  1923.             break;
  1924.         case IDM_ANIMATE_ICOSAHEDRON:
  1925.             animate_length = 10;
  1926.             RotateIcosahedron (hdc);
  1927.             break;
  1928.         case IDM_ANIMATE_SPRING:
  1929.             animate_length = 15;
  1930.             RotateSpring (hdc);
  1931.             break;
  1932.         case IDM_ANIMATE_STAR3D:
  1933.             animate_length = 15;
  1934.             RotateStar (hdc);
  1935.             break;
  1936.         case IDM_ANIMATE_DODECAHEDRON:
  1937.             animate_length = 15;
  1938.             RotateDodecahedron (hdc);
  1939.             break;
  1940.         case IDM_ANIMATE_VIEWER3D:
  1941.             animate_length = 7;
  1942.             ViewerMotion3D (hdc);
  1943.             break;
  1944.         case IDM_ANIMATE_ZOOM3D:
  1945.             animate_length = 15;
  1946.             ViewerZoom3D (hdc);
  1947.             break;
  1948.     }
  1949.     ViewerReset ();
  1950. }
  1951.  
  1952. void    Welcome (HDC hdc)
  1953. {
  1954.     char    str[80];
  1955.  
  1956.     SelectViewer (viewer20);
  1957.     PushTransformation2D (NULL);
  1958.     Scale2D (0.1f, 0.1f);
  1959.     SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1960.     TextParameter (VL_TEXT_HEIGHT, 40);
  1961.     PenColor (hdc, VL_RED);
  1962.     BrushColor (hdc, VL_YELLOW);
  1963.     wsprintf (str, "Welcome\nto\nVisuaLib");
  1964.     Text2D (hdc, 0, 0, 0, str);
  1965.     DisplayViewerFrame (hdc, VL_CURRENT);
  1966.     PopTransformation2D (NULL);
  1967. }
  1968.  
  1969. void    VlibDemo (HDC hdc, int func)
  1970. {
  1971.     BOOL    l0, l1, l2, l3;
  1972.  
  1973.     l0 = SwitchLight (light0, FALSE);
  1974.     l1 = SwitchLight (light1, FALSE);
  1975.     l2 = SwitchLight (light2, FALSE);
  1976.     l3 = SwitchLight (light3, FALSE);
  1977.     switch (func) {
  1978.         case IDM_DEMO_START:
  1979.             Welcome (hdc);
  1980.             break;
  1981.         case IDM_DEMO_SPOTLIGHT:
  1982.             SpotlightDemo (hdc);
  1983.             break;
  1984.         case IDM_DEMO_MATERIALPROPERTY:
  1985.             MaterialPropertyDemo (hdc);
  1986.             break;
  1987.         case IDM_DEMO_IMAGEMAPPING:
  1988.             ImageMappingDemo (hdc);
  1989.             break;
  1990.         case IDM_DEMO_DEPTHCLIPPING:
  1991.             DepthClippingDemo (hdc);
  1992.             break;
  1993.         case IDM_DEMO_MARBLERING:
  1994.             MarbleRingDemo (hdc);
  1995.             break;
  1996.         case IDM_DEMO_GRANITECUBE:
  1997.             GraniteCubeDemo (hdc);
  1998.             break;
  1999.         case IDM_DEMO_WOODSURFACE:
  2000.             WoodSurfaceDemo (hdc);
  2001.             break;
  2002.         case IDM_DEMO_3DCOMPOSITE:
  2003.             CompositeDemo3D (hdc);
  2004.             break;
  2005.         case IDM_DEMO_STEREOTEXT:
  2006.             StereoTextDemo (hdc);
  2007.             break;
  2008.         case IDM_DEMO_2DCOMPOSITE:
  2009.             CompositeDemo2D (hdc);
  2010.             break;
  2011.         case IDM_DEMO_NURBSCURVE:
  2012.             SelectViewer (viewer20);
  2013.             Primitives2D (hdc, IDM_2DCURVE_NURBS);
  2014.             SelectViewer (viewer30);
  2015.             Primitives3D (hdc, IDM_3DCURVE_NURBS);
  2016.             break;
  2017.     }
  2018.     SwitchLight (light0, l0);
  2019.     SwitchLight (light1, l1);
  2020.     SwitchLight (light2, l2);
  2021.     SwitchLight (light3, l3);
  2022.     SwitchLight (light4, FALSE);
  2023.     SwitchLight (light5, FALSE);
  2024.     SwitchLight (light6, FALSE);
  2025.     SwitchLight (light7, FALSE);
  2026.     SwitchLight (light8, FALSE);
  2027. }
  2028.  
  2029. void    FunctionDemos (HDC hdc)
  2030. {
  2031.     int        func = demo_function;
  2032.  
  2033.     SetROP2 (hdc, R2_COPYPEN);
  2034.     if (func > IDM_2DPRIME_START && func < IDM_2DPRIME_END) {
  2035.         SelectViewer (viewer20);
  2036.         Prime2D (hdc, func);
  2037.     }
  2038.     else if (func > IDM_3DPRIME_START && func < IDM_3DPRIME_END) {
  2039.         SelectViewer (viewer30);
  2040.         Prime3D (hdc, func);
  2041.     }
  2042.     else if (func > IDM_2DCURVE_START && func < IDM_2DCURVE_END) {
  2043.         SelectViewer (viewer20);
  2044.         Curves2D (hdc, func);
  2045.     }
  2046.     else if (func > IDM_3DCURVE_START && func < IDM_3DCURVE_END) {
  2047.         SelectViewer (viewer30);
  2048.         Curves3D (hdc, func);
  2049.     }
  2050.     else if (func >= IDM_SURFACE_START && func < IDM_SURFACE_END) {
  2051.         SelectViewer (viewer30);
  2052.         Surfaces (hdc, func);
  2053.     }
  2054.     else if (func >= IDM_SOLID_START && func < IDM_SOLID_END) {
  2055.         SelectViewer (viewer30);
  2056.         ShowSolidPrimitives (hdc, func);
  2057.     }
  2058.     else if (func > IDM_ANIMATE_START && func < IDM_ANIMATE_END) {
  2059.         AnimationDemo (hdc, func);
  2060.     }
  2061.     else if (func > IDM_TEXT_START && func < IDM_TEXT_END) {
  2062.         ShowTextPrimitives (hdc, func);
  2063.     }
  2064.     else if (func > IDM_2DTRANSF_BEGIN && func < IDM_3DTRANSF_BEGIN) {
  2065.         SelectViewer (viewer20);
  2066.         Transformation2D (hdc, func);
  2067.     }
  2068.     else if (func > IDM_3DTRANSF_BEGIN && func < IDM_3DTRANSF_END) {
  2069.         SelectViewer (viewer30);
  2070.         Transformation3D (hdc, func);
  2071.     }
  2072.     else if (func > IDM_2DPRIMIT_START && func < IDM_2DPRIMIT_END) {
  2073.         SelectViewer (viewer20);
  2074.         Primitives2D (hdc, func);
  2075.     }
  2076.     else if (func > IDM_3DPRIMIT_START && func < IDM_3DPRIMIT_END) {
  2077.         SelectViewer (viewer30);
  2078.         Primitives3D (hdc, func);
  2079.     }
  2080.     else if (func > IDM_3DARRAY_BEGIN && func < IDM_3DARRAY_END) {
  2081.         SelectViewer (viewer30);
  2082.         ObjectArray3D (hdc, func);
  2083.     }
  2084.     else if (func > IDM_2DARRAY_BEGIN && func < IDM_2DARRAY_END) {
  2085.         SelectViewer (viewer20);
  2086.         ObjectArray2D (hdc, func);
  2087.     }
  2088.     else {
  2089.         VlibDemo (hdc, func);
  2090.     }
  2091. }
  2092.  
  2093. void    AdjustViewer (HWND hwnd, int viewid)
  2094. {
  2095.     RECT    rect;
  2096.  
  2097.     GetClientRect (hwnd, &rect);
  2098.     rect.left += 10;
  2099.     rect.right -= 10;
  2100.     rect.top += 10;
  2101.     rect.bottom -= 20;
  2102.     SetViewport (viewid, rect);
  2103. }
  2104.  
  2105. BINARY    SavePicture (HWND hwnd, BOOL withframe)
  2106. {
  2107.     RECT    rect;
  2108.     HANDLE    hdib;
  2109.     BOOL    flag;
  2110.  
  2111.     GetScreenRect (hwnd, withframe, &rect);
  2112.     hdib = ScreenToDIB (&rect);
  2113.     if (!hdib)
  2114.         return (FALSE);
  2115.     flag = WriteDIBFile (NULL, hdib);
  2116.     GlobalUnlock (hdib);
  2117.     GlobalFree (hdib);
  2118.     return (flag);
  2119. }
  2120.  
  2121. BINARY    PrintPicture (HWND hwnd, BOOL withframe)
  2122. {
  2123.     RECT    rect;
  2124.     HANDLE    hdib;
  2125.     BOOL    flag;
  2126.  
  2127.     GetScreenRect (hwnd, withframe, &rect);
  2128.     hdib = ScreenToDIB (&rect);
  2129.     if (!hdib)
  2130.         return (FALSE);
  2131.     flag = PrintImage (hdib,
  2132.         VL_BESTFIT | VL_VERTCENTER | VL_HORZCENTER | VL_MARKCORNER,
  2133.         0, 0, 0, 0);
  2134.     GlobalUnlock (hdib);
  2135.     GlobalFree (hdib);
  2136.     return (flag);
  2137. }
  2138.  
  2139. void    PrintFlag (void)
  2140. {
  2141.     SelectViewer (viewer22);
  2142.     PrintDrawing (USFlag,
  2143.         VL_BESTFIT | VL_HORZCENTER | VL_VERTCENTER | VL_MARKCORNER,
  2144.         0, 0, 0, 0);
  2145. }
  2146.  
  2147. void    ExitDemo (void)
  2148. {
  2149.     ExitVisualib ();
  2150.     GlobalUnlock (hdib1);
  2151.     GlobalFree (hdib1);
  2152.     GlobalUnlock (hdib2);
  2153.     GlobalFree (hdib2);
  2154.     GlobalUnlock (hdib3);
  2155.     GlobalFree (hdib3);
  2156.     PostQuitMessage (0);
  2157. }
  2158.  
  2159. void    AlterMenuItem (HWND hwnd, WORD entry)
  2160. {
  2161.     short    flag = MF_BYCOMMAND;
  2162.  
  2163.     switch (entry) {
  2164.         case IDM_DEMO_WITHFRAME:
  2165.             withframe = !withframe;
  2166.             flag |= (withframe) ? MF_CHECKED : MF_UNCHECKED;
  2167.             break;
  2168.     }
  2169.     CheckMenuItem (GetMenu (hwnd), entry, flag);
  2170. }
  2171.                         
  2172. /****************************************************************************
  2173.  
  2174.     FUNCTION: MainWndProc (HWND, WORD, WORD, LONG)
  2175.  
  2176.     PURPOSE:  Processes messages
  2177.  
  2178.     MESSAGES:
  2179.  
  2180.     WM_COMMAND  - application menu (About dialog box)
  2181.     WM_DESTROY  - destroy window
  2182.  
  2183.     COMMENTS:
  2184.  
  2185.     To process the IDM_ABOUT message, call MakeProcInstance () to get the
  2186.     current instance address of the About () function.  Then call Dialog
  2187.     box which will create the box according to the information in your
  2188.     vlibdemo.rc file and turn control over to the About () function.    When
  2189.     it returns, free the intance address.
  2190.  
  2191. ****************************************************************************/
  2192.  
  2193. long WINAPI MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  2194. {
  2195.     switch (msg) {
  2196.         case WM_COMMAND:
  2197.             switch (wParam) {
  2198.                 case IDM_DEMO_EXIT:
  2199.                     ExitDemo ();
  2200.                     break;
  2201.                 case IDM_HELP_ABOUT:
  2202.                     AboutVisualib ();
  2203.                     SendMessage (hWnd, WM_COMMAND, IDM_DEMO_START, 0L);
  2204.                     break;
  2205.                 case IDM_HELP_LICENSE:
  2206.                     LicenseInfo ();
  2207.                     break;
  2208.                 case IDM_HELP_DEMOPROG:
  2209.                     WinHelp (hWnd, "vlibdemo.hlp", HELP_INDEX, 0);
  2210.                     break;
  2211.                 case IDM_HELP_VISUALIB:
  2212.                     WinHelp (hWnd, "visualib.hlp", HELP_INDEX, 0);
  2213.                     break;
  2214.                 case IDM_DEMO_SAVEPICTURE:
  2215.                     SavePicture (hWnd, withframe);
  2216.                     break;
  2217.                 case IDM_DEMO_PRINTPICTURE:
  2218.                     PrintPicture (hWnd, withframe);
  2219.                     break;
  2220.                 case IDM_DEMO_WITHFRAME:
  2221.                     AlterMenuItem (hWnd, wParam);
  2222.                     break;
  2223.                 case IDM_DEMO_PRINTFLAG:
  2224.                     PrintFlag ();
  2225.                     break;
  2226.                 case IDM_TEXT_SELECTFONT:
  2227.                     SelectFont ();
  2228.                     return (NULL);
  2229.                 default:
  2230.                     if (wParam > 200 && wParam < 300) {
  2231.                         ShadingSettings (hWnd, wParam);
  2232.                         break;
  2233.                     }
  2234.                     if (wParam > IDM_ANIMATE_START &&
  2235.                         wParam < IDM_ANIMATE_END) {
  2236.                         HDC    hdc;
  2237.  
  2238.                         hdc = GetDC (hWnd);
  2239.                         AnimationDemo (hdc, wParam);
  2240.                         ReleaseDC (hWnd, hdc);
  2241.                         break;
  2242.                     }
  2243.                     demo_function = wParam;
  2244.                     InvalidateRect (hWnd, NULL, TRUE);
  2245.                     return (DefWindowProc (hWnd, msg, wParam, lParam));
  2246.             }
  2247.             break;
  2248.         case WM_DESTROY:
  2249.             ExitVisualib ();
  2250.             GlobalUnlock (hdib1);
  2251.             GlobalFree (hdib1);
  2252.             GlobalUnlock (hdib2);
  2253.             GlobalFree (hdib2);
  2254.             GlobalUnlock (hdib3);
  2255.             GlobalFree (hdib3);
  2256.             PostQuitMessage (0);
  2257.             break;
  2258.  
  2259.         case WM_PAINT:
  2260.             ProcessWindowPaint (hWnd);
  2261.             break;
  2262.         
  2263.         case WM_SIZE:
  2264.             AdjustViewer (hWnd, viewer20);
  2265.             AdjustViewer (hWnd, viewer30);
  2266.             InvalidateRect (hWnd, NULL, TRUE);
  2267.             break;
  2268.  
  2269.         default:
  2270.             return (DefWindowProc (hWnd, msg, wParam, lParam));
  2271.     }
  2272.     return (NULL);
  2273. }
  2274.  
  2275.